import axios from "axios";
import config from "@/config/config.js";
import menuRequest from "@/api/menu.js";
import PlanEdit from "@/views/machineType/machineMaintainPlanEdit.vue";

const maintainPlanRequest={
    components: {PlanEdit},
    loadPlan(plan,page=1,limit=10,callBack){
        let url = config.typeBaseUrl+"/plan/list?page="+page+"&limit="+limit;
        if (plan){
            if (plan.planCode){
                url += "&planCode=" +plan.planCode;
            }
            if (plan.planName){
                url += "&planName=" +plan.planName;
            }
            if (plan.planType){
                url += "&planType=" +plan.planType;
            }
            if (plan.planStatus){
                url += "&planStatus=" +plan.planStatus;
            }
            axios.get(url).then(res=>{
                callBack(res.data);
            })
        }
    },

    addPlan(plan,callBack){
        let url = config.typeBaseUrl +"/plan/add";
        axios.put(url,plan).then(res=>{
            callBack(res.data);
        })
    },

    updatePlan(plan,callBack){
        let url = config.typeBaseUrl + "/plan/updatePlan"
        axios.put(url,plan).then(res=>{
            callBack(res.data);
        })
    },

    selectById(planId,callBack) {
        let url = config.typeBaseUrl + "/plan/selectById?planId=" + planId;
        axios.get(url).then(res => {
            callBack(res.data);
        })
    },

    deletePlan(planId,callBack){
        let url = config.typeBaseUrl +"/plan/updatePlanStatus?planId="+planId;
        axios.put(url).then(res=>{
            callBack(res.data);
        })
    }

}
export default maintainPlanRequest;